/*
 * Principal.java
 *
 * Created on 22/04/2011, 00:45:07
 */

package tp1.views;

import tp1.controllers.Controller;
import javax.swing.JPanel;

/**
 *
 * @author tulio
 */
public class Principal extends javax.swing.JFrame {

    private static Principal instance = null;

    private Principal() {
        this.setTitle("Sistema de gerenciamento telefônico");
        initComponents();
        initControllers();
    }

    public static Principal getInstance(){
        if(instance == null) {
            instance = new Principal();
        }
        return instance;
    }
    
    public void showView(JPanel view){
        getContentPane().removeAll();
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(view, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(view, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        repaint();
        pack();
    }

    private void initControllers(){
        Controller controllerCliente = Controller.factory(Controller.CONTROLLER_CLIENTE, new ClientePanel());
        controllerCliente.addEvent(menuCliente, Controller.EVENTO_ABRIR_TELA_CLIENTE);
        menuCliente.addActionListener(controllerCliente);

        Controller controllerPlano = Controller.factory(Controller.CONTROLLER_PLANO, new PlanoPanel());
        controllerPlano.addEvent(menuPlano, Controller.EVENTO_ABRIR_TELA_PLANO);
        menuPlano.addActionListener(controllerPlano);

        Controller controllerLinha = Controller.factory(Controller.CONTROLLER_LINHA, new LinhaPanel());
        controllerLinha.addEvent(menuLinha, Controller.EVENTO_ABRIR_TELA_LINHA);
        menuLinha.addActionListener(controllerLinha);
        
        Controller controllerChamada = Controller.factory(Controller.CONTROLLER_CHAMADA, new ChamadaPanel());
        controllerChamada.addEvent(menuChamada, Controller.EVENTO_ABRIR_TELA_CHAMADA);
        menuChamada.addActionListener(controllerChamada);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        content = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        menu = new javax.swing.JMenuBar();
        menuCadastros = new javax.swing.JMenu();
        menuCliente = new javax.swing.JMenuItem();
        menuPlano = new javax.swing.JMenuItem();
        menuLinha = new javax.swing.JMenuItem();
        menuChamada = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Ubuntu", 0, 48)); // NOI18N
        jLabel1.setText("Alô Telecomunicações S.A.");

        javax.swing.GroupLayout contentLayout = new javax.swing.GroupLayout(content);
        content.setLayout(contentLayout);
        contentLayout.setHorizontalGroup(
            contentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, contentLayout.createSequentialGroup()
                .addContainerGap(201, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 599, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(171, 171, 171))
        );
        contentLayout.setVerticalGroup(
            contentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contentLayout.createSequentialGroup()
                .addGap(159, 159, 159)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(196, Short.MAX_VALUE))
        );

        menuCadastros.setText("Cadastros");

        menuCliente.setText("Cliente");
        menuCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuClienteActionPerformed(evt);
            }
        });
        menuCadastros.add(menuCliente);

        menuPlano.setText("Plano");
        menuCadastros.add(menuPlano);

        menuLinha.setText("Linha");
        menuCadastros.add(menuLinha);

        menuChamada.setText("Chamada");
        menuCadastros.add(menuChamada);

        menu.add(menuCadastros);

        setJMenuBar(menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(content, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(content, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void menuClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuClienteActionPerformed
    }//GEN-LAST:event_menuClienteActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel content;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuBar menu;
    private javax.swing.JMenu menuCadastros;
    private javax.swing.JMenuItem menuChamada;
    private javax.swing.JMenuItem menuCliente;
    private javax.swing.JMenuItem menuLinha;
    private javax.swing.JMenuItem menuPlano;
    // End of variables declaration//GEN-END:variables

}
